Imports Microsoft.VisualBasic
Imports System.Xml
Imports System.Xml.XmlNode
Imports System.Xml.Serialization

<Serializable()> _
Public Class TrainingSetup
    Inherits BaseSetup




    Private _pointsForFullTraining As Integer 'ideal attribute incremental point for full training

    Private _trainingType As String 'either position or category
    Private _trainingTypeSel As String 'either position or category

    Private _trainingAffecting As String 'either positions or zones
    Private _trainingAffectingSel As String 'either positions or zones

    Private _trainingAgeMap As Hashtable 'how does this training affect young vs old players.

    'how does this training affect players in different positions.

    'positions
    Private _gk As Integer

    Private _sw As Integer
    Private _rb As Integer
    Private _rwb As Integer
    Private _rcb As Integer
    Private _cb As Integer
    Private _lcb As Integer
    Private _lwb As Integer
    Private _lb As Integer

    Private _rm As Integer
    Private _ram As Integer
    Private _rcm As Integer
    Private _rdm As Integer
    Private _cm As Integer
    Private _cam As Integer
    Private _cdm As Integer
    Private _ldm As Integer
    Private _lcm As Integer
    Private _lam As Integer
    Private _lm As Integer

    Private _rw As Integer
    Private _rf As Integer
    Private _rs As Integer
    Private _cf As Integer
    Private _st As Integer
    Private _ls As Integer
    Private _lf As Integer
    Private _lw As Integer


    'zones
    Private _keeper As Integer
    Private _defense As Integer
    Private _midfield As Integer
    Private _forward As Integer









    Public Sub New()
        _trainingAgeMap = New Hashtable
        For Each key As String In Cons.GET_AGERANGES
            _trainingAgeMap.Add(key, "0")
        Next

    End Sub


#Region "PROPERTIES"


    Public Property TrainingType() As String
        Get
            Return _trainingType
        End Get
        Set(ByVal value As String)
            _trainingType = value
        End Set
    End Property

    Public Property TrainingTypeSelected() As String
        Get
            Return _trainingTypeSel
        End Get
        Set(ByVal value As String)
            _trainingTypeSel = value
        End Set
    End Property

    Public Property TrainingAffecting() As String
        Get
            Return _trainingAffecting
        End Get
        Set(ByVal value As String)
            _trainingAffecting = value
        End Set
    End Property

    Public Property TrainingAffectingSelected() As String
        Get
            Return _trainingAffectingSel
        End Get
        Set(ByVal value As String)
            _trainingAffectingSel = value
        End Set
    End Property

    Public Property TrainingAgeMap() As Hashtable
        Get
            Return _trainingAgeMap
        End Get
        Set(ByVal value As Hashtable)
            _trainingAgeMap = value
        End Set
    End Property

    Public Property PointsForFUllTraining() As Integer
        Get
            Return Me._pointsForFullTraining
        End Get
        Set(ByVal value As Integer)
            Me._pointsForFullTraining = value
        End Set
    End Property


    Public Property GK() As Integer
        Get
            Return _gk
        End Get
        Set(ByVal value As Integer)
            _gk = value
        End Set
    End Property

    Public Property SW() As Integer
        Get
            Return _sw
        End Get
        Set(ByVal value As Integer)
            _sw = value
        End Set
    End Property

    Public Property RB() As Integer
        Get
            Return _rb
        End Get
        Set(ByVal value As Integer)
            _rb = value
        End Set
    End Property

    Public Property RWB() As Integer
        Get
            Return _rwb
        End Get
        Set(ByVal value As Integer)
            _rwb = value
        End Set
    End Property

    Public Property RCB() As Integer
        Get
            Return _rcb
        End Get
        Set(ByVal value As Integer)
            _rcb = value
        End Set
    End Property

    Public Property CB() As Integer
        Get
            Return _cb
        End Get
        Set(ByVal value As Integer)
            _cb = value
        End Set
    End Property

    Public Property LCB() As Integer
        Get
            Return _lcb
        End Get
        Set(ByVal value As Integer)
            _lcb = value
        End Set
    End Property

    Public Property LWB() As Integer
        Get
            Return _lwb
        End Get
        Set(ByVal value As Integer)
            _lwb = value
        End Set
    End Property

    Public Property LB() As Integer
        Get
            Return _lb
        End Get
        Set(ByVal value As Integer)
            _lb = value
        End Set
    End Property



    Public Property RM() As Integer
        Get
            Return _rm
        End Get
        Set(ByVal value As Integer)
            _rm = value
        End Set
    End Property

    Public Property RAM() As Integer
        Get
            Return _ram
        End Get
        Set(ByVal value As Integer)
            _ram = value
        End Set
    End Property

    Public Property RCM() As Integer
        Get
            Return _rcm
        End Get
        Set(ByVal value As Integer)
            _rcm = value
        End Set
    End Property

    Public Property RDM() As Integer
        Get
            Return _rdm
        End Get
        Set(ByVal value As Integer)
            _rdm = value
        End Set
    End Property

    Public Property LDM() As Integer
        Get
            Return _ldm
        End Get
        Set(ByVal value As Integer)
            _ldm = value
        End Set
    End Property

    Public Property CM() As Integer
        Get
            Return _cm
        End Get
        Set(ByVal value As Integer)
            _cm = value
        End Set
    End Property

    Public Property CAM() As Integer
        Get
            Return _cam
        End Get
        Set(ByVal value As Integer)
            _cam = value
        End Set
    End Property

    Public Property CDM() As Integer
        Get
            Return _cdm
        End Get
        Set(ByVal value As Integer)
            _cdm = value
        End Set
    End Property

    Public Property LCM() As Integer
        Get
            Return _lcm
        End Get
        Set(ByVal value As Integer)
            _lcm = value
        End Set
    End Property

    Public Property LAM() As Integer
        Get
            Return _lam
        End Get
        Set(ByVal value As Integer)
            _lam = value
        End Set
    End Property

    Public Property LM() As Integer
        Get
            Return _lm
        End Get
        Set(ByVal value As Integer)
            _lm = value
        End Set
    End Property



    Public Property RW() As Integer
        Get
            Return _rw
        End Get
        Set(ByVal value As Integer)
            _rw = value
        End Set
    End Property

    Public Property RF() As Integer
        Get
            Return _rf
        End Get
        Set(ByVal value As Integer)
            _rf = value
        End Set
    End Property

    Public Property RS() As Integer
        Get
            Return _rs
        End Get
        Set(ByVal value As Integer)
            _rs = value
        End Set
    End Property

    Public Property CF() As Integer
        Get
            Return _cf
        End Get
        Set(ByVal value As Integer)
            _cf = value
        End Set
    End Property

    Public Property ST() As Integer
        Get
            Return _st
        End Get
        Set(ByVal value As Integer)
            _st = value
        End Set
    End Property

    Public Property LS() As Integer
        Get
            Return _ls
        End Get
        Set(ByVal value As Integer)
            _ls = value
        End Set
    End Property

    Public Property LF() As Integer
        Get
            Return _lf
        End Get
        Set(ByVal value As Integer)
            _lf = value
        End Set
    End Property

    Public Property LW() As Integer
        Get
            Return _lw
        End Get
        Set(ByVal value As Integer)
            _lw = value
        End Set
    End Property





    Public Property Keeper() As Integer
        Get
            Return _keeper
        End Get
        Set(ByVal value As Integer)
            _keeper = value
        End Set
    End Property

    Public Property Defense() As Integer
        Get
            Return _defense
        End Get
        Set(ByVal value As Integer)
            _defense = value
        End Set
    End Property

    Public Property Midfield() As Integer
        Get
            Return _midfield
        End Get
        Set(ByVal value As Integer)
            _midfield = value
        End Set
    End Property

    Public Property Forward() As Integer
        Get
            Return Me._forward
        End Get
        Set(ByVal value As Integer)
            _forward = value
        End Set
    End Property


#End Region


    Public Function GetPosition(ByVal pos As String) As Integer

        Select Case (pos)

            Case Cons.POSITION_GK
                Return GK
            Case Cons.POSITION_SW
                Return SW
            Case Cons.POSITION_RB
                Return RB
            Case Cons.POSITION_RWB
                Return RWB
            Case Cons.POSITION_RCB
                Return RCB
            Case Cons.POSITION_CB
                Return CB
            Case Cons.POSITION_LCB
                Return LCB
            Case Cons.POSITION_LWB
                Return LWB
            Case Cons.POSITION_LB
                Return LB
            Case Cons.POSITION_RM
                Return RM
            Case Cons.POSITION_RAM
                Return RAM
            Case Cons.POSITION_RCM
                Return RCM
            Case Cons.POSITION_CM
                Return CM
            Case Cons.POSITION_CAM
                Return CAM
            Case Cons.POSITION_CDM
                Return CDM
            Case Cons.POSITION_LCM
                Return LCM
            Case Cons.POSITION_LAM
                Return LAM
            Case Cons.POSITION_LM
                Return LM
            Case Cons.POSITION_RW
                Return RW
            Case Cons.POSITION_RF
                Return RF
            Case Cons.POSITION_RS
                Return RS
            Case Cons.POSITION_CF
                Return CF
            Case Cons.POSITION_ST
                Return ST
            Case Cons.POSITION_LS
                Return LS
            Case Cons.POSITION_LF
                Return LF
            Case Cons.POSITION_LW
                Return LW

        End Select

    End Function

    Public Function GetZone(ByVal zone As String) As Integer

        Select Case (zone)

            Case Cons.ZONE_Keeper
                Return Keeper
            Case Cons.ZONE_Defense
                Return Defense
            Case Cons.ZONE_Midfield
                Return Midfield
            Case Cons.ZONE_Forward
                Return Forward
        End Select

    End Function

    Public Overrides Function SetupToXML() As String
        Dim xml As String = ""

        xml &= "<Setup>"

        xml &= "<pointsforfulltraining>" & Me._pointsForFullTraining & "</pointsforfulltraining>"

        xml &= "<TrainingAgesSetup>"
        For Each s As String In Cons.GET_AGERANGES
            xml &= "<" & s & ">" & _trainingAgeMap(s) & "</" & s & ">"
        Next
        xml &= "</TrainingAgesSetup>"

        xml &= "<trainingtype>" & Me._trainingType & "</trainingtype>"
        xml &= "<trainingtypeselected>" & Me._trainingTypeSel & "</trainingtypeselected>"

        xml &= "<trainingaffecting>" & Me._trainingAffecting & "</trainingaffecting>"
        xml &= "<trainingaffectingselected>" & Me._trainingAffectingSel & "</trainingaffectingselected>"

        xml &= "<TrainingPositions>"

        xml &= "<gk>" & Me._gk & "</gk>"
        xml &= "<sw>" & Me._sw & "</sw>"
        xml &= "<rb>" & Me._rb & "</rb>"
        xml &= "<rwb>" & Me._rwb & "</rwb>"
        xml &= "<rcb>" & Me._rcb & "</rcb>"
        xml &= "<cb>" & Me._cb & "</cb>"
        xml &= "<lcb>" & Me._lcb & "</lcb>"
        xml &= "<lwb>" & Me._lwb & "</lwb>"
        xml &= "<lb>" & Me._lb & "</lb>"

        xml &= "<rm>" & Me._rm & "</rm>"
        xml &= "<ram>" & Me._ram & "</ram>"
        xml &= "<rcm>" & Me._rcm & "</rcm>"
        xml &= "<rdm>" & Me._rdm & "</rdm>"
        xml &= "<cm>" & Me._cm & "</cm>"
        xml &= "<cam>" & Me._cam & "</cam>"
        xml &= "<cdm>" & Me._cdm & "</cdm>"
        xml &= "<ldm>" & Me._lcm & "</ldm>"
        xml &= "<lcm>" & Me._lcm & "</lcm>"
        xml &= "<lam>" & Me._lam & "</lam>"
        xml &= "<lm>" & Me._lm & "</lm>"

        xml &= "<rw>" & Me._gk & "</rw>"
        xml &= "<rf>" & Me._rf & "</rf>"
        xml &= "<rs>" & Me._rs & "</rs>"
        xml &= "<cf>" & Me._cf & "</cf>"
        xml &= "<st>" & Me._st & "</st>"
        xml &= "<ls>" & Me._ls & "</ls>"
        xml &= "<lf>" & Me._lf & "</lf>"
        xml &= "<lw>" & Me._lw & "</lw>"

        xml &= "</TrainingPositions>"

        xml &= "<TrainingZones>"
        xml &= "<keeper>" & Me._keeper & "</keeper>"
        xml &= "<defense>" & Me._defense & "</defense>"
        xml &= "<midfield>" & Me._midfield & "</midfield>"
        xml &= "<forward>" & Me._forward & "</forward>"
        xml &= "</TrainingZones>"

        xml &= "</Setup>"
        Return xml
    End Function

    Public Overrides Function XMLToSetup(ByVal xml As String) As BaseSetup
        Dim doc As New XmlDocument
        If (xml.Length > 0 And Not xml.Equals("<Setup />")) Then
            doc.LoadXml(xml)

            _pointsForFullTraining = doc.GetElementsByTagName("pointsforfulltraining").ItemOf(0).InnerText

            _trainingType = doc.GetElementsByTagName("trainingtype").ItemOf(0).InnerText
            _trainingTypeSel = doc.GetElementsByTagName("trainingtypeselected").ItemOf(0).InnerText

            _trainingAffecting = doc.GetElementsByTagName("trainingaffecting").ItemOf(0).InnerText
            _trainingAffectingSel = doc.GetElementsByTagName("trainingaffectingselected").ItemOf(0).InnerText


            '_trainingMap = New Hashtable
            Dim value As String
            For Each key As String In Cons.GET_AGERANGES
                value = doc.GetElementsByTagName(key).ItemOf(0).InnerText
                _trainingAgeMap.Item(key) = value
                '_trainingMap.Add(key, value)
            Next

            _gk = doc.GetElementsByTagName("gk").ItemOf(0).InnerText

            _sw = doc.GetElementsByTagName("sw").ItemOf(0).InnerText
            _rb = doc.GetElementsByTagName("rb").ItemOf(0).InnerText
            _rwb = doc.GetElementsByTagName("rwb").ItemOf(0).InnerText
            _rcb = doc.GetElementsByTagName("rcb").ItemOf(0).InnerText
            _cb = doc.GetElementsByTagName("cb").ItemOf(0).InnerText
            _lcb = doc.GetElementsByTagName("lcb").ItemOf(0).InnerText
            _lwb = doc.GetElementsByTagName("lwb").ItemOf(0).InnerText
            _lb = doc.GetElementsByTagName("lb").ItemOf(0).InnerText

            _rm = doc.GetElementsByTagName("rm").ItemOf(0).InnerText
            _ram = doc.GetElementsByTagName("ram").ItemOf(0).InnerText
            _rcm = doc.GetElementsByTagName("rcm").ItemOf(0).InnerText
            _rdm = doc.GetElementsByTagName("rdm").ItemOf(0).InnerText
            _cm = doc.GetElementsByTagName("cm").ItemOf(0).InnerText
            _cam = doc.GetElementsByTagName("cam").ItemOf(0).InnerText
            _cdm = doc.GetElementsByTagName("cdm").ItemOf(0).InnerText
            _ldm = doc.GetElementsByTagName("ldm").ItemOf(0).InnerText
            _lcm = doc.GetElementsByTagName("lcm").ItemOf(0).InnerText
            _lam = doc.GetElementsByTagName("lam").ItemOf(0).InnerText
            _lm = doc.GetElementsByTagName("lm").ItemOf(0).InnerText

            _rw = doc.GetElementsByTagName("rw").ItemOf(0).InnerText
            _rf = doc.GetElementsByTagName("rf").ItemOf(0).InnerText
            _rs = doc.GetElementsByTagName("rs").ItemOf(0).InnerText
            _cf = doc.GetElementsByTagName("cf").ItemOf(0).InnerText
            _st = doc.GetElementsByTagName("st").ItemOf(0).InnerText
            _ls = doc.GetElementsByTagName("ls").ItemOf(0).InnerText
            _lf = doc.GetElementsByTagName("lf").ItemOf(0).InnerText
            _lw = doc.GetElementsByTagName("lw").ItemOf(0).InnerText

            _keeper = doc.GetElementsByTagName("keeper").ItemOf(0).InnerText
            _defense = doc.GetElementsByTagName("defense").ItemOf(0).InnerText
            _midfield = doc.GetElementsByTagName("midfield").ItemOf(0).InnerText
            _forward = doc.GetElementsByTagName("forward").ItemOf(0).InnerText


        End If




        Return Me
    End Function

    Public Overrides Function Clone() As BaseSetup

    End Function

    Public Overrides Function ToString() As String

    End Function

    Public Overrides Function ValidateBaseSetup() As Collection
        Dim errList As New Collection
        Dim errRow As ErrorRow

        Dim total As Double = 0

        For Each percent As Double In _trainingAgeMap.Values

            total += percent
        Next

        If total <> 100.0 Then
            errRow = New ErrorRow
            errRow.Field = "Training Age Ranges"
            errRow.Value = total
            errRow.Message = "Age Range % total must be equal to 100%."
            errList.Add(errRow)

        End If

        Return errList
    End Function

    Public Overrides Function DefaultXML() As String
        Dim xml As String = ""

        xml &= "<Setup>"

        xml &= "<pointsforfulltraining>0</pointsforfulltraining>"

        xml &= "<TrainingAgesSetup>"
        'For Each s As String In Cons.GET_AGERANGES
        '    xml &= "<" & s & ">0</" & s & ">"
        'Next

        xml &= "<AgeRange1>100</AgeRange1>"
        xml &= "<AgeRange2>0</AgeRange2>"
        xml &= "<AgeRange3>0</AgeRange3>"
        xml &= "<AgeRange4>0</AgeRange4>"
        xml &= "<AgeRange5>0</AgeRange5>"
        xml &= "<AgeRange6>0</AgeRange6>"
        xml &= "<AgeRange7>0</AgeRange7>"

        xml &= "</TrainingAgesSetup>"

        xml &= "<trainingtype>" & Cons.TRAINING_TYPE_Attribute & "</trainingtype>"
        xml &= "<trainingtypeselected>" & Cons.ATTRIBUTE_Crossing & "</trainingtypeselected>"

        xml &= "<trainingaffecting>" & Cons.TRAINING_AFFECTING_Positions & "</trainingaffecting>"
        xml &= "<trainingaffectingselected>null</trainingaffectingselected>"

        xml &= "<TrainingPositions>"

        xml &= "<gk>0</gk>"
        xml &= "<sw>0</sw>"
        xml &= "<rb>0</rb>"
        xml &= "<rwb>0</rwb>"
        xml &= "<rcb>0</rcb>"
        xml &= "<cb>0</cb>"
        xml &= "<lcb>0</lcb>"
        xml &= "<lwb>0</lwb>"
        xml &= "<lb>0</lb>"

        xml &= "<rm>0</rm>"
        xml &= "<ram>0</ram>"
        xml &= "<rcm>0</rcm>"
        xml &= "<rdm>0</rdm>"
        xml &= "<cm>0</cm>"
        xml &= "<cam>0</cam>"
        xml &= "<cdm>0</cdm>"
        xml &= "<ldm>0</ldm>"
        xml &= "<lcm>0</lcm>"
        xml &= "<lam>0</lam>"
        xml &= "<lm>0</lm>"

        xml &= "<rw>0</rw>"
        xml &= "<rf>0</rf>"
        xml &= "<rs>0</rs>"
        xml &= "<cf>0</cf>"
        xml &= "<st>0</st>"
        xml &= "<ls>0</ls>"
        xml &= "<lf>0</lf>"
        xml &= "<lw>0</lw>"

        xml &= "</TrainingPositions>"

        xml &= "<TrainingZones>"
        xml &= "<keeper>0</keeper>"
        xml &= "<defense>0</defense>"
        xml &= "<midfield>0</midfield>"
        xml &= "<forward>0</forward>"
        xml &= "</TrainingZones>"

        xml &= "</Setup>"
        Return xml
    End Function
End Class
